/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import Beans.Poke;
import datas.PokesMapper;
import java.util.List;
import org.apache.ibatis.session.SqlSession;

/**

 @author Marie-Claude
 */
public class PokeDao {

  public static List<Poke> getAllByUserId(int userId) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {

      PokesMapper mapper = session.getMapper(PokesMapper.class);
      List<Poke> lstPokes = mapper.getAllByUserId(userId);
      return lstPokes;

    } finally {
      MyBatisManager.closeConnexion();
    }
  }

  public static void sendWink(Poke poke) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {

      PokesMapper mapper = session.getMapper(PokesMapper.class);
      mapper.insert(poke);
      session.commit();

    } finally {
      MyBatisManager.closeConnexion();
    }
  }

  public static void deleteWinks(int userId) {
    SqlSession session = MyBatisManager.getSqlSession();

    try {

      PokesMapper mapper = session.getMapper(PokesMapper.class);
      mapper.delete(userId);
      session.commit();

    } finally {
      MyBatisManager.closeConnexion();
    }
  }
}
